package gd.qaq.blue.flauntitem.util;

import gd.qaq.blue.flauntitem.FlauntItem;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.Plugin;


@SuppressWarnings("all")
public class PluginHelper {

    public static FileConfiguration loadData(Plugin plugin) {
        if (!plugin.getDataFolder().exists()) {
            plugin.getDataFolder().mkdirs();
            plugin.saveDefaultConfig();
        }
        return plugin.getConfig();
    }

    public static FileConfiguration reload(Plugin plugin, CommandSender p) {
        if (p.isOp()) {
            try {
                plugin.reloadConfig();
                success(p, "插件重载成功");
                return plugin.getConfig();
            } catch (Exception e) {
                e.printStackTrace();
                error(p, "插件重载失败!");
            }
        }
        return null;
    }

    public static String colorFormat(String str) {
        return str.replace("&", "§");
    }

    public static void success(CommandSender p, String str) {
        p.sendMessage(colorFormat(FlauntItem.config.getString("plugin.prefix.success") + str));
    }

    public static void error(CommandSender p, String str) {
        p.sendMessage(colorFormat(FlauntItem.config.getString("plugin.prefix.error") + str));
    }
}
